﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;

namespace theguineasyndrome.levels
{
    public class MarioLevel : LevelLoader
    {

        public MarioLevel(GameMode gameMode, ContentManager content, WaterWeapon waterWeapon, FireWeapon fireWeapon, PortalWeapon portalWeapon, PaintWeapon paintWeapon)
            : base(gameMode, content, waterWeapon, fireWeapon, portalWeapon, paintWeapon)
        {

        }

        private void movingPlatformUpdater(ObstacleElement element, GameTime gameTime)
        {
            element.Position = level.getPointMarkPosition("UpAndDown plateform") + new Vector2(0, (float)Math.Cos(gameTime.TotalGameTime.TotalSeconds) * 300);

            if (element.Character != null)
                element.Character.setPosition(element.Position + element.CharacterRelativePosition);
        }

        public override Level load()
        {
            level = getLevel("levels/level");
            //level = getCustomLevel("level");

            Texture2D goombaTexture = content.Load<Texture2D>("images/enemies/goomba");
            for (int i = 1; i <= 5; i++)
                level.addElement(new Goomba(level, goombaTexture, level.getPointMarkPosition("enemyMushroom " + i)));

            Texture2D turtleTexture = content.Load<Texture2D>("images/enemies/turtle");
            for (int i = 1; i <= 4; i++)
                level.addElement(new Turtle(level, turtleTexture, level.getPointMarkPosition("enemyTortue " + i)));

            Texture2D beeTexture = content.Load<Texture2D>("images/enemies/bee");
            Texture2D beeRopeTexture = content.Load<Texture2D>("images/enemies/beerope");
            for (int i = 1; i <= 3; i++)
                level.addElement(new Bee(level, beeTexture, beeRopeTexture, level.getPointMarkPosition("enemyBee " + i)));

            Texture2D cloudTexture = content.Load<Texture2D>("images/level/level/obstacles/cloud");
            ObstacleElement movingPlatform = new ObstacleElement(level, cloudTexture, level.getPointMarkPosition("UpAndDown plateform"));
            movingPlatform.setUpdater(movingPlatformUpdater);
            level.addElement(movingPlatform);

            addCarots(level);

            Song song = content.Load<Song>("music/SnowMan attack");
            MediaPlayer.Stop();
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(song);

            return level;
        }

    }
}
